﻿using DAL.comm;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class SystemUserDAL
    {
        private SqlCommand cmd;
        public SystemUserDAL()
        {

            cmd = new SqlCommand();//实例化sqlcommand对象
            cmd.CommandType = CommandType.StoredProcedure;//定义sqlmmand对象访问数据库方式为存储过程
        }
        public bool UserLogin(string UserID, string Password)
        {

            cmd.CommandText = "UserLogin";//存储过程名
            cmd.Parameters.Clear();//清空存储过程参数
            cmd.Parameters.Add("@UserID", SqlDbType.NVarChar, 6).Value = UserID;//添加存储过程参数
            cmd.Parameters.Add("@Password", SqlDbType.NVarChar, 10).Value = Password;//添加存储过程参数


            int num = Convert.ToInt32(SQLHelper.GetScalar(cmd));
            try
            {
                if (num > 0)
                {
                    return true;
                }
                else
                    return false;

            }
            catch
            {

                return false;
            }

        }
        ///获取列表
        public List<SystemUser> GetList()
        {
            cmd.CommandText = "SelectSystemUserList";//存储过程名
            cmd.Parameters.Clear();//清空存储过程参数
            List<SystemUser> list = new List<SystemUser>();
            SqlDataReader reader = SQLHelper.ExcuteReader(cmd);//读库 
            while (reader.Read())
            {
                SystemUser bo = new SystemUser();
                bo.UserID = reader["UserID"].ToString().Trim();
                bo.BaseFunction = int.Parse(reader["BaseFunction"].ToString());
                bo.PurchaseFunction = int.Parse(reader["PurchaseFunction"].ToString());
                bo.SaleFunction = int.Parse(reader["SaleFunction"].ToString());
                bo.UserFunction = int.Parse(reader["UserFunction"].ToString());
                list.Add(bo);
            }
            reader.Close();//关闭读库
            return list;
        }
    }
}
